﻿using Adnc.Application.Shared;
using Adnc.WebApi.Shared;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using WYT.Sys.Application.Contracts.Dtos.Common;
using WYT.Sys.Application.Contracts.Services;

namespace WYT.Sys.WebApi.Controllers
{
    /// <summary>
    /// 公共基础服务
    /// </summary>
    [Route("sys/[Controller]")]
    [ApiController]
    public class CommonController : AdncControllerBase
    {
        private readonly ICommonAppService _commonAppService;

        private readonly IUserContext _userContext;

        public CommonController(ICommonAppService commonAppService
            , IUserContext userContext)
        {
            _commonAppService = commonAppService;
            _userContext = userContext;
        }

        /// <summary>
        /// 下级地址查询
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpGet("subarea")]
        [AllowAnonymous]
        public async  Task<WYTActionResult<List<AreaDto>>> SubAreaSearch([FromQuery] AreaSearchDto input)
        {
            return Success(await _commonAppService.AreaQuery(input));
        }
        /// <summary>
        /// 获取广告或者banner
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpGet("banner")]
        public async Task<WYTActionResult<List<BannerDto>>> GetBannerList([FromQuery] BannerSearchDto input)
        {
            return Success(await _commonAppService.GetBannerList(input));
        }

        /// <summary>
        /// 提交反馈
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost("feedback")]
        public async Task<WYTActionResult> SubmitFeedBack(FeedbackDto input)
        {
            return Success(await _commonAppService.SubmitFeedBack(_userContext.Id, input));
        }
    }
}
